//
//  Contact.m
//  Depressed.domo
//
//  Created by rimi on 16/5/31.
//  Copyright © 2016年 薛涛. All rights reserved.
//

#import "Contact.h"

@implementation Contact

-(instancetype)initWithDictionary:(NSDictionary *)info {
    self = [super init];
    if (self) {
        // KVC(Key Value Coding)键值编码：可以在不知道类的具体实现的时候，访问类对象的属性，使用key访问；首先访问与"key"同名或"_key"的属性，若没找到则访问与"key"同名或"_key"的成员变量，若最终没找到，则程序崩溃。
        for (NSString *key in info) {
            [self setValue:info[key] forKey:key];
        }
    }
    return self;
}

- (NSString *)description {
    return [NSString stringWithFormat:@"name = %@ age = %@ sex = %@",_name,_age,_sex];
}

/**归档*/
- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:_name forKey:@"name"];
    [aCoder encodeObject:_age forKey:@"age"];
    [aCoder encodeObject:_sex forKey:@"sex"];
}

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];
    if (self) {
        _name = [aDecoder decodeObjectForKey:@"name"];
        _age = [aDecoder decodeObjectForKey:@"age"];
        _sex = [aDecoder decodeObjectForKey:@"sex"];
    }
    return self;
}
@end
